package a_math;

import java.util.Calendar;
import java.util.Date;

/**
 * @author Cheng-02
 * @version V1.0
 * @Package a_math
 * @date 2024/4/6 14:28
 */
public class test05 {
    public static void main(String[] args) {
        calender02();
    }

    private static void calender02() {
//        int get(int field) ->返回给定日历字段的值
        Calendar calendar = Calendar.getInstance();
        int year = calendar.get(Calendar.YEAR);
        System.out.println(year);
//        void set(int field,int value)：给定的日历字段设置为指定的值
        calendar.set(Calendar.YEAR, 2024);
        System.out.println(calendar.get(Calendar.YEAR));
//        void add(int field,int amount)：根据日历的规则，为给定的日历字段添加或者减去指定的时间量
        calendar.add(Calendar.YEAR, -1);
        System.out.println(calendar.get(Calendar.YEAR));

//        Date getTime()：将Calendar转换成date对象
        Date date = calendar.getTime();
        System.out.println(date);
    }

    private static void calender01() {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar);
    }
}
